import 'package:app/jspangStudy/widget/dragMove.dart';
import 'package:flutter/material.dart';

class KeepAliveCom extends StatefulWidget {
  @override
  _KeepAliveComState createState() => _KeepAliveComState();
}

class _KeepAliveComState extends State<KeepAliveCom>
    with AutomaticKeepAliveClientMixin {
  int _count = 0;
  Color _color = Colors.pinkAccent;

  @override
  bool get wantKeepAlive => true; // 保存页面(页面状态不销毁)

  void _incrementCounter() {
    setState(() {
      _count++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('点一次增加一'),
            Text('$_count'),
            RaisedButton(
              onPressed: () {
                _incrementCounter();
              },
              child: Text('增加'),
            ),
            DargMoveWidget(
              offset: Offset(80, 80),
              color: Colors.red,
            ),
            DargMoveWidget(
              offset: Offset(100, 100),
              color: Colors.greenAccent,
            ),
            Center(
              child: DragTarget(
                // 拖拽接收器
                onAccept: (Color color) {
                  _color = color;
                },
                builder: (context, candidateData, rejectedData) {
                  // 构造器
                  return Container(
                    height: 200,
                    width: 200,
                    color: _color,
                  );
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
